package com.shangcheng.server.controller;

import com.shangcheng.model.domain.SmsFlashPromotionProductRelation;
import com.shangcheng.model.vo.PageResult;
import com.shangcheng.model.vo.result.Result;
import com.shangcheng.server.service.SmsFlashPromotionProductRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 批量选择商品添加关联
 */
@RestController
@RequestMapping("flashProductRelation")
public class SmsFlashPromotionProductRelationController {

    @Autowired
    private SmsFlashPromotionProductRelationService smsFlashPromotionProductRelationService;

    /**
     * 添加活动和产品关系
     *
     * @param relationList
     * @return
     */
    @PostMapping("create")
    public Result create(@RequestBody List<SmsFlashPromotionProductRelation> relationList) {
        smsFlashPromotionProductRelationService.create(relationList);
        return new Result(200, null, "添加成功");
    }

    /**
     * 删除活动和产品关系
     *
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        smsFlashPromotionProductRelationService.delete(id);
        return new Result(200, null, "删除成功");
    }

    /**
     * 查询全部场次
     *
     * @return
     */
    @GetMapping("list")
    public Result findAllSmsHomeAdvertiselist(Integer flashPromotionId, Integer flashPromotionSessionId,
                                              @RequestParam(defaultValue = "1") Integer pageNum,
                                              @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult pr = smsFlashPromotionProductRelationService.findList(flashPromotionId,
                flashPromotionSessionId, pageNum, pageSize);
        return new Result(200, pr, "");
    }

    /**
     * 修改场次
     *
     * @param id
     * @param relation
     * @return
     */
    @PostMapping("update/{id}")
    public Result update(@PathVariable("id") Integer id, @RequestBody SmsFlashPromotionProductRelation relation) {
        smsFlashPromotionProductRelationService.update(id, relation);
        return new Result(200, null, "修改成功");
    }

    /**
     * 获取场次详情
     *`
     * @param id
     * @return
     */
    @PostMapping("/{id}")
    public Result update(@PathVariable("id") Integer id) {
        SmsFlashPromotionProductRelation smsFlashPromotionProductRelation = smsFlashPromotionProductRelationService.findById(id);
        return new Result(200, smsFlashPromotionProductRelation, "");
    }

}
